import { getCategory } from '@/services';
import { Icategory } from '@/types';
import { Effect, ImmerReducer, Reducer, Subscription } from 'umi';

export interface CategoryModelState {
    archivesPage: Icategory[]
}

export interface CategoryModelType {
    namespace: 'category';
    state: CategoryModelState;
    effects: {
        getCategory: Effect;
    };
    reducers: {
        save: Reducer<CategoryModelState>;
    };
}

const CategoryModel: CategoryModelType = {
    namespace: 'category',

    state: {
        //文章分类数据
        archivesPage: [],
    },

    effects: {
        // 归档文章分类
        *getCategory({ payload }, { call, put }) {
            const result = yield call(getCategory)
            // console.log(result.data, "result.dataresult.dataresult.dataresult.dataresult.datav");
            if (result.data) {
                yield put({
                    type: "save",
                    payload: {
                        archivesPage: result.data
                    }
                })
            }
        }

    },
    reducers: {
        save(state, action) {
            return {
                ...state,
                ...action.payload,
            };
        },
    },
};

export default CategoryModel;